package com.banciyuan.bcywebview.biz.detail.comment;


import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.view.View;

import com.banciyuan.bcywebview.R;
import com.banciyuan.bcywebview.base.helper.timelinedatacenter.DetailDataHelper;
import com.banciyuan.bcywebview.base.util.BaseObserver;
import com.banciyuan.bcywebview.base.view.dialog.ChooseDialog;
import com.banciyuan.bcywebview.biz.detail.EditActivity;
import com.banciyuan.bcywebview.biz.report.ReportActivity;
import com.banciyuan.bcywebview.utils.intent.gotoUtil;

import de.greenrobot.daoexample.model.DetailComment;
import de.greenrobot.daoexample.model.DetailType;

public class DetailCommentHolder extends BaseViewComment {
    private String mCommentId;
    private View ivShark;
    private View viewCommentsContainer;

    public DetailCommentHolder(View convertView, String commentId, String workAuthorUid, String commentAuthorUid) {
        super(convertView);
        super.setCommonIds(workAuthorUid, commentAuthorUid);
        mCommentId = commentId;
        ivShark = convertView.findViewById(R.id.iv_shark);
        viewCommentsContainer = convertView.findViewById(R.id.ll_comments_container);
    }

    @Override
    public void setData(int position, DetailComment comment, Context context, boolean at, DetailType detailType, boolean isComment) {
        super.setData(position, comment, context, at, detailType, isComment);
        comment_iv.setVisibility(View.GONE);
        ivShark.setVisibility(View.GONE);
        viewCommentsContainer.setBackgroundColor(mContext.getResources().getColor(R.color.white));
    }

    @Override
    protected void setReplys(DetailComment comment, Context context) {
        llReplyContainer.setVisibility(View.GONE);
    }

    @Override
    protected void doReply() {
        Intent intent = new Intent(mContext, EditActivity.class);
        intent.putExtra(CommentConstants.COMMENT_TYPE, 4);
        intent.putExtra(CommentConstants.UNAME, detailComment.getUname());
        intent.putExtra(CommentConstants.CONTENT, detailComment.getContent());
        intent.putExtra(CommentConstants.SHOW_CHARGE, false);
        intent.putExtra(CommentConstants.COMMENT_ID, mCommentId);
        intent.putExtra(CommentConstants.COMMENT_POS, position);
        DetailDataHelper.putBaseDetailValue(intent, detailType);
        ((Activity) mContext).startActivityForResult(intent, CommentConstants.GO_REPLY);
        ((Activity) mContext).overridePendingTransition(R.anim.umeng_socialize_fade_in, R.anim.umeng_socialize_fade_out);
    }

    @Override
    protected void doRepost() {
        Intent intent = new Intent(mContext, ReportActivity.class);
        DetailDataHelper.putBaseDetailValue(intent, detailType);
        intent.putExtra(gotoUtil.INTENT_VALUE_ONE, isComment ? 3 : 1);
        intent.putExtra(gotoUtil.INTENT_VALUE_TWO, mCommentId);
        intent.putExtra(gotoUtil.INTENT_VALUE_THREE, detailComment.getId());
        mContext.startActivity(intent);
    }

    @Override
    protected void deleteCommit() {
        mCommentDetailHelper.deleteReply(mCommentId, detailComment.getId(), new IGetComment() {
            @Override
            public void getSucc(String json) {
                BaseObserver.getInstance().notifyWatchers(BaseObserver.DELELE_REPLY_EVENT, detailComment);
                isLoading = false;
            }

            @Override
            public void getFail() {
                isLoading = false;
            }
        });
    }

    @Override
    protected void setLineAuthorBuilder(View.OnClickListener replyOnClick, View.OnClickListener deleteOnClick, View.OnClickListener copyOnClick) {
        ChooseDialog.Builder builder = new ChooseDialog.Builder(mContext);
        builder.setChooseOneString(mContext.getString(R.string.copy_paste))
                .setChooseOneClick(copyOnClick)
                .setChooseTwoString(mContext.getString(R.string.mydialog_delete))
                .setChooseTwoClick(deleteOnClick)
                .create().show();
    }

    protected void doZan(IZanComment iZanComment) {
        ZanCommentHelper zanCommentHelper = new ZanCommentHelper(iZanComment, mContext);
        if (!detailComment.getHave_ding()) {
            zanCommentHelper.doPraiseRepley(detailType, detailComment.getId(), mCommentId);
        } else {
            zanCommentHelper.unDoPraiseRepley(detailType, detailComment.getId(), mCommentId);
        }
    }
}
